package com.example.exportsql.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.exportsql.entity.TableStruct;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 廖半仙
 * @date 2025/5/21
 */
@Mapper
public interface MyMapper extends BaseMapper<TableStruct> {

    @Select("Show tables")
    List<String> getAllTables();

    @Select("SELECT DATABASE()")
    String getDatabase();

    @Select("select \n" +
            "column_name as field,\n" +
            "data_type as type,\n" +
            "column_comment as comment,\n" +
            "IF(is_nullable='YES','是','否') as tnull,\n" +
            "IF(column_key= 'PRI','主键','') as tkey,\n" +
            "IFNULL(column_default,'NULL') as tdefault\n" +
            " from information_schema.columns\n" +
            "where table_schema = #{database} \n" +
            "and table_name = #{tableName} ORDER BY ordinal_position")
    List<TableStruct> getTableInfo(@Param("tableName") String tableName, @Param("database") String database);
//
//    @Select("SHOW FULL FIELDS FROM ${tableName}")
//    List<TableStruct> getTableInfo(@Param("tableName") String tableName);
}
